<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.data.ConnData" %>
<%
    request.setCharacterEncoding("utf-8");
    String questionId = request.getParameter("question_id");

    ConnData objdata = new ConnData();
    Connection connection = null;
    PreparedStatement psmt = null;
    try {
        connection = objdata.getConn();
        String sql = "DELETE FROM question_table WHERE question_id =?";
        psmt = objdata.getPsmt(sql);
        psmt.setString(1, questionId);
        int rowsAffected = psmt.executeUpdate();
        if (rowsAffected > 0) {
            // 重定向回题目列表页面，展示删除后的最新结果
            response.sendRedirect("admin.jsp");
        }
    } catch (SQLException e) {
        e.printStackTrace();
%>
<p>数据库操作出现错误，请稍后再试！</p>
<%
        // 同样可以考虑添加返回相关的链接，方便用户操作
        // out.println("<a href='question_list.jsp'>返回题目列表</a>");
    } finally {
        if (psmt != null) {
            try {
                psmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
%>